﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetSysData;

namespace BladeTecWebApplication.Admin
{
    public partial class EditApplicant : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                NetSysData.NetSysData data = new NetSysData.NetSysData();
                pnlConfirmationForm.Visible = false;
                int applicant_id;
                APPLICANT applicant;
                try
                {
                    applicant_id = Int32.Parse(Request.QueryString["applicant_id"]);
                }
                catch (Exception)
                {
                    // show error
                    return;
                }

                if (Request.QueryString["applicant_id"] != "")
                {
                    applicant = data.GetApplicant(applicant_id);
                    if (applicant == null)
                    {
                        // show error
                        return;
                    }
                }
                else
                {
                    // show error
                    return;
                }

                txtFirstName.Text = applicant.FIRST_NAME;
                txtLastName.Text = applicant.LAST_NAME;
                txtPhone.Text = applicant.PHONE_NUMBER;
                KeyLabel.Text = applicant.APPLICANT_KEY;
                txtEmail.Text = applicant.EMAIL;

                
                
                hfdate.Value = applicant.INTERVIEW_DATE.ToString();

                DateTime dt = Convert.ToDateTime(hfdate.Value);
                hfdate0.Value = dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString();
                hfApplicantId0.Value = applicant_id.ToString();
                
              

                ddlPositions.Items.Add(new ListItem("Select ...", ""));
                POSITION[] positions = data.GetPositions();
                foreach (POSITION position in positions)
                {
                    ddlPositions.Items.Add(new ListItem(position.POSITION_TITLE, position.POSITION_ID.ToString()));
                }
                ddlPositions.SelectedIndex = applicant.POSITION_ID;
                
            }

        }
 


        protected void btnAddApplicant_Click(object sender, EventArgs e)
        {
            NetSysData.NetSysData data = new NetSysData.NetSysData();

            APPLICANT a = data.GetApplicant(Int32.Parse(hfApplicantId0.Value));
            a.FIRST_NAME = txtFirstName.Text;
            a.LAST_NAME = txtLastName.Text;
            a.PHONE_NUMBER = txtPhone.Text;
            a.EMAIL = txtEmail.Text;
            a.INTERVIEW_DATE = DateTime.Parse(hfdate.Value);
           

            data.Save();

            lblAName.Text = a.FIRST_NAME + " " + a.LAST_NAME;

            newApplicantForm.Visible = false;
            pnlConfirmationForm.Visible = true;


            //redirect
            //Server.Transfer("~/Admin/ViewApplicants.aspx", true);
            
        }
        
    }
}